local skill = fk.CreateSkill {
  name = "#ling__modao_skill",
  attached_equip = "ling__modao",
}

Fk:loadTranslationTable{
  ["#ling__modao_skill"] = "陌刀",
  ["#ling__modao1-choose"] = "陌刀：你可以弃置所有手牌，为%arg额外指定至多两个目标",
  ["#ling__modao2-choose"] = "陌刀：你可以弃置两张手牌，为%arg额外指定至多两个目标",
}

skill:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and data.card.trueName == "slash" and
      #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local ids = table.filter(player:getCardIds("h"), function(id)
      return not player:prohibitDiscard(id)
    end)
    if #ids <= 2 then
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 2,
        targets = data:getExtraTargets(),
        skill_name = skill.name,
        prompt = "#ling__modao1-choose:::"..data.card:toLogString(),
        cancelable = true,
      })
      if #to > 0 then
        event:setCostData(self, {tos = to, cards = ids})
        return true
      end
    else
      local to, cards = room:askToChooseCardsAndPlayers(player, {
        min_card_num = 2,
        max_card_num = 2,
        min_num = 1,
        max_num = 2,
        targets = data:getExtraTargets(),
        pattern = ".|.|.|hand",
        skill_name = skill.name,
        prompt = "#ling__modao2-choose:::"..data.card:toLogString(),
        cancelable = true,
        will_throw = true,
      })
      if #to > 0 and #cards == 2 then
        event:setCostData(self, {tos = to, cards = cards})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, p in ipairs(event:getCostData(self).tos) do
      data:addTarget(p)
    end
    local cards = event:getCostData(self).cards
    if #cards > 0 then
      player.room:throwCard(cards, skill.name, player, player)
    end
  end,
})

return skill
